//
//  NetworkHandle.m
//  Tour
//
//  Created by dllo on 15/8/18.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "NetworkHandle.h"

@implementation NetworkHandle

+ (void)GETWithURL:(NSString *)urlStr competion:(void (^)(id))block
{
    
    NSString *str = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
 
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:str]];
    
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError)
     {
        if (data != nil) {
            
            id result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
            block(result);
            
        }
        else
        {
            NSLog(@"无网络");
            id result = nil;
            block(result);
        }
        
    }];
    
}

@end
